/****************************************************************************
	This file is part of Basqet.

	Basqet is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Basqet is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
    along with Basqet.  If not, see <http://www.gnu.org/licenses/>.

****************************************************************************/

#include "timeanddatedisplay.h"
#include "ui_timeanddatedisplay.h"

#include <QTimer>
#include <QDate>
#include <QTime>


TimeAndDateDisplay::TimeAndDateDisplay(QWidget *parent) :
    QWidget(parent),
	ui(new Ui::TimeAndDateDisplay),
	pTimer(0)
{
    ui->setupUi(this);

	pTimer = new QTimer(this);
	connect(pTimer, SIGNAL(timeout()), this, SLOT(updateTime()));
	pTimer->start(3000);

	updateTime();

}

TimeAndDateDisplay::~TimeAndDateDisplay()
{
    delete ui;
}

void TimeAndDateDisplay::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}


void TimeAndDateDisplay::updateTime()
{
	int wYear;
	int weekNo = QDate::currentDate().weekNumber(&wYear);

    QString weekStr;

    if (weekNo < 10)
        weekStr = QString("W%1%2%3").arg(wYear%10).arg("0").arg(weekNo);
    else
        weekStr = QString("W%1%2").arg(wYear%10).arg(weekNo);


	ui->pWeek->setText(weekStr);
	ui->pDate->setText(QDate::currentDate().toString("yyyy-MM-dd"));
	ui->pTime->setText(QTime::currentTime().toString("hh:mm"));

}
